//
//  UMengHandler.m
//  MyFamework
//
//  Created by carlos on 13-9-8.
//  Copyright (c) 2013年 carlos. All rights reserved.
//

#import "UMengHandler.h"
#import "MobClick.h"
@implementation UMengHandler
#pragma mark 系统的生命周期方法
+ (void) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    CLog(@"UMengHandler didFinishLaunchingWithOptions");
    [self umengInit];
}

//友盟的初始化

+ (void)umengInit{
    //(使用建议，建议使用REALTIME策略，数据实时性更高， channelId 为nil或@""时，默认会被被当作@"App Store"渠道) 其中ReportPolicy可选值有: REALTIME,BATCH,SENDDAILY,SENDWIFIONLY。
    [MobClick startWithAppkey:kCgUmengKey reportPolicy:REALTIME channelId:kCgChannelID];
    [MobClick updateOnlineConfig];
    [MobClick setCrashReportEnabled:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onlineConfigCallBack:) name:UMOnlineConfigDidFinishedNotification object:nil];
}

//从友盟上获取在线参数的通知回调
+ (void)onlineConfigCallBack:(NSNotification *)notification {
    //    NSLog(@"online config has fininshed and params = %@", notification.userInfo);
    NSString *baseUrl = [MobClick getConfigParams:@"base_v3_url"];
    //    CLog(@"baseUrl = %@",baseUrl);
    //    DLog(@"%@",[MobClick getConfigParams:@"base_url"]);
    [InterfaceDefineClass setBaseUrl:baseUrl];
    
}
@end
